home *** CD-ROM | disk | FTP | other *** search
Wrap
Text File | 2008-06-16 | 83.8 KB | 2,390 lines
const LOAD_FLAGS_NONE = 0; const LOAD_FLAGS_IS_REFRESH = 16; const LOAD_FLAGS_IS_LINK = 32; const LOAD_FLAGS_BYPASS_HISTORY = 64; const LOAD_FLAGS_REPLACE_HISTORY = 128; const LOAD_FLAGS_BYPASS_CACHE = 256; const LOAD_FLAGS_BYPASS_PROXY = 512; const LOAD_FLAGS_CHARSET_CHANGE = 1024; const LOAD_FLAGS_MASK = 65535; const STOP_NETWORK = 1; const STOP_CONTENT = 2; const STOP_ALL = 3; const CLIPMARKS_VERSION = '3.5.0'; const CLIPMARKS_ENABLE_VIDEO = true; var CLIPMARKS_URL_FIRST_TIME_INSTALL = 'clipmarks.com/installed/firefox/'; var CLIPMARKS_URL_UPGRADE_INSTALL = 'clipmarks.com/upgraded/firefox/'; var CLIPMARKS_URL_HOME = 'clipmarks.com/'; var CLIPMARKS_URL_SAVE_CLIP = 'clipmarks.com/clip_mozilla_save.aspx'; var CLIPMARKS_URL_EDIT_CLIP = 'clipmarks.com/edit_clip.aspx'; var CLIPMARKS_URL_PRINT_CLIP = 'clipmarks.com/print_clips_direct.aspx'; var CLIPMARKS_URL_EMAIL_CLIP = 'clipmarks.com/email_clipmark.aspx'; var CLIPMARKS_URL_BLOG_CLIP = 'clipmarks.com/blog_this.aspx'; var CLIPMARKS_URL_PUBLIC_LIBRARY = 'clipmarks.com/public/'; var CLIPMARKS_URL_LATEST_POPS = 'clipmarks.com/sort/latest-pops/'; var CLIPMARKS_URL_MY_LIBRARY = 'clipmarks.com/login.aspx?url=/mine/'; var CLIPMARKS_URL_MY_PROFILE = 'clipmarks.com/profile/edit/'; var CLIPMARKS_URL_MY_WIDGET = 'clipmarks.com/login.aspx?url=/my.clipcast/'; var CLIPMARKS_URL_MY_CLIPPERS = 'clipmarks.com/login.aspx?url=/my.clipcast/clippers/'; var CLIPMARKS_URL_HOT = 'clipmarks.com/popular/'; var CLIPMARKS_URL_CLASSIC = 'clipmarks.com/popular/'; var CLIPMARKS_URL_HOW_TO_CLIP = 'clipmarks.com/how-to-clip/'; var CLIPMARKS_URL_PUBLISHING_LIMIT = 'clipmarks.com/publishing-limit/'; var CLIPMARKS_URL_SETTINGS = 'chrome://clipmarks/content/feed_supported_video.xml'; var CLIPMARKS_URL_UNINSTALL = 'clipmarks.com/uninstall.aspx'; var CLIPMARKS_URL_FACEBOOK = 'http://apps.facebook.com/clipmarks/'; var CLIPMARKS_URL_HELP = 'http://clipmarks.com/faq/'; var Clipmarks_Preferences = { _pref : null, get : function (stringa, predefinito) { if (this._pref==null) this._pref = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch); try { if (typeof(predefinito) == "boolean") { var scelta = this._pref.getBoolPref(stringa); } else if (typeof(predefinito) == "string") { var scelta = this._pref.getCharPref(stringa); } else if (typeof(predefinito) == "number") { var scelta = this._pref.getIntPref(stringa); } return scelta; } catch (e) { if (typeof(predefinito) == "boolean") { var scelta = this._pref.setBoolPref(stringa, predefinito); } else if (typeof(predefinito) == "string") { var scelta = this._pref.setCharPref(stringa, predefinito); } else { var scelta = this._pref.setIntPref(stringa, predefinito); } return predefinito; } }, set : function(stringa, value) { if (this._pref==null) { this._pref = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch); } if (typeof(value) == "boolean") { this._pref.setBoolPref(stringa, value); } else if (typeof(value) == "string") { this._pref.setCharPref(stringa, value); } else if (typeof(value) == "number") { this._pref.setIntPref(stringa, value); } }, removeBranch: function(pref) { try { this._pref.deleteBranch(pref); } catch(e) {} } } function Clipmarks_GetAppName() { var name = "unknown"; try { var app = Components.classes["@mozilla.org/xre/app-info;1"].getService(Components.interfaces.nsIXULAppInfo).QueryInterface(Components.interfaces.nsIXULRuntime); var id = app.ID; switch(id) { case "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}": name = "firefox"; break; case "{3550f703-e582-4d05-9a08-453d09bdfdc6}": name = "thunderbird"; break; case "{86c18b42-e466-45a9-ae7a-9b95ba6f5640}": name = "mozilla"; break; case "{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}": name = "seamonkey"; break; case "{a463f10c-3994-11da-9945-000d60ca027b}": name = "flock"; break; } } catch(e) {} return name; } function Clipmarks_GetAppVersion() { var ver = null; try { var app = Components.classes["@mozilla.org/xre/app-info;1"].getService(Components.interfaces.nsIXULAppInfo).QueryInterface(Components.interfaces.nsIXULRuntime); ver = app.version; } catch(e) {} return ver; } function Clipmarks_UninstallObserver() { this._observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService); this._observerService.addObserver(this, "em-action-requested", false); this._guid = '{e1170235-2845-420c-acc3-42261a29dd46}'; var appName = Clipmarks_GetAppName(); if (!appName || (appName == 'unknown')) { appName = '-'; } var appVersion = Clipmarks_GetAppVersion(); if (!appVersion) { appVersion = "-"; } this._uninstallURL = CLIPMARKS_URL_UNINSTALL; this._uninstallURL += '?version=' + CLIPMARKS_VERSION; this._uninstallURL += '&app=' + appName; this._uninstallURL += '&app-version=' + appVersion; Clipmarks_Preferences.set('extensions.clipmarks.uninstall_screen_shown', false); } Clipmarks_UninstallObserver.prototype = { observe: function(subject, topic, data) { if ((topic == "em-action-requested") && (data == "item-uninstalled")) { var bUninstallScreenShown = Clipmarks_Preferences.get('extensions.clipmarks.uninstall_screen_shown', false); if (bUninstallScreenShown) return; Clipmarks_Preferences.set('extensions.clipmarks.uninstall_screen_shown', true); var updateItem = subject.QueryInterface(Components.interfaces.nsIUpdateItem); if (updateItem.id == this._guid) { Clipmarks_set_location(this._uninstallURL, null, true); } } }, removeObserver : function() { this._observerService.removeObserver(this, "em-action-requested"); } }; var aryEmbed = new Array(); var Clipmarks_ClipXML = null; var Clipmarks_SettingsXML = null; var Clipmarks_ClipMode = 0; var Clipmarks_BaseElement = null; var Clipmarks_ActiveElement = null; var Clipmarks_ClipElements = new Array(); var Clipmarks_ClipOverlays = new Array(); var Clipmarks_Initialized = false; var Clipmarks_ContextMenuVisible = false; var Clipmarks_ElementIsColumn = false; var Clipmarks_IsContentSelected = false; var Clipmarks_XMLHTTP = null; var Clipmarks_IsMac = (navigator.userAgent.toLowerCase().indexOf("mac")!=-1); var Clipmarks_CancelClick = false; var Clipmarks_PrintClicked = false; var Clipmarks_EmailClicked = false; var Clipmarks_BlogClicked = false; var Clipmarks_UseBorders = true; var Clipmarks_PageLeft = 0; var Clipmarks_PageTop = 0; var Clipmarks_CancelMouseUp = false; var Clipmarks_ClipElementIndex = 0; var Clipmarks_BorderLeftId = 'Clipmarks1' + (Math.round((Math.random()*1000))) + 'BorderDiv' + (Math.round((Math.random()*10000))); var Clipmarks_BorderRightId = 'Clipmarks2' + (Math.round((Math.random()*1000))) + 'BorderDiv' + (Math.round((Math.random()*10000))); var Clipmarks_BorderTopId = 'Clipmarks3' + (Math.round((Math.random()*1000))) + 'BorderDiv' + (Math.round((Math.random()*10000))); var Clipmarks_BorderBottomId = 'Clipmarks4' + (Math.round((Math.random()*1000))) + 'BorderDiv' + (Math.round((Math.random()*10000))); var Clipmarks_iFrameCount = 0; var Clipmarks_CharCount = 0; var gClipmarks_UninstallObserver = null; var gClipmarks_EndDocumentLoadObserver = null; var Clipmarks_SiblingsChecked = 0; function Clipmarks_getNavigationBar(toolbox) { var navBar = null; for (var i = 0; i < toolbox.childNodes.length; i++ ) { var toolbar = toolbox.childNodes[i]; if (toolbar.localName == "toolbar" && toolbar.id == "nav-bar" && toolbar.getAttribute("customizable")=="true" ) { navBar = toolbar; break; } } return navBar; } function Clipmarks_addToToolbar(toolbox, toolbar) { var toolbarObjects = Clipmarks_SplitX(toolbar.currentSet, ',' ); var length = toolbarObjects.length; Clipmarks_checkAddButton('Clipmarks-Toolbar', 'search-container', toolbarObjects, ( length > 0 ) ); if ( length != toolbarObjects.length ) { var newBarSet = Clipmarks_XasString(toolbarObjects, ','); toolbar.currentSet = newBarSet; toolbar.setAttribute('currentset', toolbar.currentSet); toolbox.ownerDocument.persist(toolbar.id, 'currentset'); try { BrowserToolboxCustomizeDone(true); } catch ( e ) {} } } function Clipmarks_XasString( arr, sep ) { var str = ''; for ( var i = 0; i < arr.length; i++ ) { if ( i > 0 ) { str = str + sep; } str = str + arr[ i ]; } return str; } function Clipmarks_SplitX(str, separators, returnSeparators ) { var tokens = []; var buffer = ""; for ( var i = 0; i < str.length; i++ ) { var ch = str.charAt( i ); if ( separators.indexOf( ch ) != -1 ) { if ( buffer != "" ) { tokens[ tokens.length ] = buffer; } if ( returnSeparators ) { tokens[ tokens.length ] = ch; } buffer = ""; } else { buffer = buffer + ch; } } if ( buffer != "" ) { tokens[ tokens.length ] = buffer; } return tokens; } function Clipmarks_checkAddButton(btn, pivot, toolbarObjects, doInsert ) { if ( !doInsert ) { toolbarObjects.push( btn ); } else { if ( toolbarObjects.indexOf( btn ) == -1 ) { var pivotIndex = toolbarObjects.indexOf( pivot ); if ( pivotIndex == -1 ) { pivotIndex = 0; while ( pivotIndex < toolbarObjects.length) { pivotIndex++; } } toolbarObjects.splice( pivotIndex, 0, btn ); } } } function Clipmarks_set_location(uri, postdata, new_tab) { var browser = getBrowser(); if (new_tab) { var tab = browser.addTab(uri, Clipmarks_get_nsiuri(browser.contentDocument.referrer), null, (postdata == null) ? null : Clipmarks_get_mime_input_stream(postdata, "application/x-www-form-urlencoded")); browser.selectedTab = tab; } else { browser.webNavigation.loadURI(uri, Components.interfaces.nsIWebNavigation.LOAD_FLAGS_NONE, Clipmarks_get_nsiuri(browser.contentDocument.referrer), (postdata == null) ? null : Clipmarks_get_mime_input_stream(postdata, "application/x-www-form-urlencoded"), null); } } function Clipmarks_get_mime_input_stream(str, content_type) { var data_stream = Components.classes["@mozilla.org/io/string-input-stream;1"].createInstance(Components.interfaces.nsIStringInputStream); data_stream.setData(str, str.length); var mime_stream = Components.classes["@mozilla.org/network/mime-input-stream;1"].createInstance(Components.interfaces.nsIMIMEInputStream); mime_stream.addHeader("Content-Type", content_type); mime_stream.addContentLength = true; mime_stream.setData(data_stream); return mime_stream.QueryInterface(Components.interfaces.nsIInputStream); } function Clipmarks_get_nsiuri(uri_str) { var URI = Components.Constructor("@mozilla.org/network/standard-url;1", "nsIURI"); var uri = new URI; uri.spec = uri_str; return uri; } var lBorderKey = 66; var lClipKey = 67; addEventListener("unload", Clipmarks_UnInit, false); window.addEventListener( "load", function () { gBrowser.addEventListener("pageshow", Clipmarks_Init, true); }, false ); function Clipmarks_KeyPress(event) { if (event.ctrlKey && event.shiftKey && event.charCode == 66) { Clipmarks_EnableOrangeLines(); } else if (event.ctrlKey && event.shiftKey && event.charCode == 67) { Clipmarks_Clip(event); } } function Clipmarks_EnableOrangeLines(bForceOff) { if (bForceOff || Clipmarks_Preferences.get('extensions.clipmarks.use-borders', 1) == 1) { Clipmarks_Preferences.set('extensions.clipmarks.use-borders', 0); Clipmarks_UseBorders = false; window.document.getElementById('Clipmarks_OrangeLinesCheckbox').src = 'chrome://clipmarks/skin/lines-unchecked.gif'; } else { Clipmarks_Preferences.set('extensions.clipmarks.use-borders', 1); Clipmarks_UseBorders = true; window.document.getElementById('Clipmarks_OrangeLinesCheckbox').src = 'chrome://clipmarks/skin/lines-checked.gif'; } } function Clipmarks_GetSettings() { Clipmarks_XMLHTTP = new XMLHttpRequest(); Clipmarks_XMLHTTP.open('GET', CLIPMARKS_URL_SETTINGS, true); Clipmarks_XMLHTTP.onreadystatechange = Clipmarks_SettingsStateChange; Clipmarks_XMLHTTP.send(null); } function Clipmarks_SettingsStateChange() { if (Clipmarks_XMLHTTP.readyState != 4) { return; } if (!Clipmarks_XMLHTTP.responseXML) { return; } Clipmarks_SettingsXML = Clipmarks_XMLHTTP.responseXML; } function Clipmarks_Init(event) { var oDocument = (!event.target.ownerDocument ? event.target : event.target.ownerDocument); if (Clipmarks_Initialized) { if (Clipmarks_ClipMode == 1) { Clipmarks_iFrameCount = 0; //Clipmarks_ShowModeStatus(oDocument); Clipmarks_FixPage(oDocument); //Clipmarks_HideModeStatus(oDocument); } return; } else { var bFirstUse = false; var sSitePrefix = Clipmarks_Preferences.get('extensions.clipmarks.site-prefix', ''); document.getElementById('appcontent').insertBefore(document.getElementById('Clipmarks-SaveBar'), document.getElementById('content')); if (sSitePrefix != '') { sSitePrefix += '.'; } CLIPMARKS_URL_FIRST_TIME_INSTALL = 'http://' + sSitePrefix + CLIPMARKS_URL_FIRST_TIME_INSTALL; CLIPMARKS_URL_UPGRADE_INSTALL = 'http://' + sSitePrefix + CLIPMARKS_URL_UPGRADE_INSTALL; CLIPMARKS_URL_LATEST_POPS = 'http://clipcast.' + sSitePrefix + CLIPMARKS_URL_LATEST_POPS; CLIPMARKS_URL_SAVE_CLIP = 'http://' + sSitePrefix + CLIPMARKS_URL_SAVE_CLIP; CLIPMARKS_URL_EDIT_CLIP = 'http://' + sSitePrefix + CLIPMARKS_URL_EDIT_CLIP; CLIPMARKS_URL_PRINT_CLIP = 'http://' + sSitePrefix + CLIPMARKS_URL_PRINT_CLIP; CLIPMARKS_URL_EMAIL_CLIP = 'http://' + sSitePrefix + CLIPMARKS_URL_EMAIL_CLIP; CLIPMARKS_URL_BLOG_CLIP = 'http://' + sSitePrefix + CLIPMARKS_URL_BLOG_CLIP; CLIPMARKS_URL_HOME = 'http://' + sSitePrefix + CLIPMARKS_URL_HOME; CLIPMARKS_URL_PUBLIC_LIBRARY = 'http://' + sSitePrefix + CLIPMARKS_URL_PUBLIC_LIBRARY; CLIPMARKS_URL_MY_LIBRARY = 'http://' + sSitePrefix + CLIPMARKS_URL_MY_LIBRARY; CLIPMARKS_URL_MY_WIDGET = 'http://' + sSitePrefix + CLIPMARKS_URL_MY_WIDGET; CLIPMARKS_URL_MY_PROFILE = 'http://' + sSitePrefix + CLIPMARKS_URL_MY_PROFILE; CLIPMARKS_URL_MY_CLIPPERS = 'http://' + sSitePrefix + CLIPMARKS_URL_MY_CLIPPERS; CLIPMARKS_URL_HOT = 'http://clipcast.' + sSitePrefix + CLIPMARKS_URL_HOT; CLIPMARKS_URL_CLASSIC = 'http://' + sSitePrefix + CLIPMARKS_URL_CLASSIC; CLIPMARKS_URL_HOW_TO_CLIP = 'http://' + sSitePrefix + CLIPMARKS_URL_HOW_TO_CLIP; CLIPMARKS_URL_PUBLISHING_LIMIT = 'http://' + sSitePrefix + CLIPMARKS_URL_PUBLISHING_LIMIT; CLIPMARKS_URL_UNINSTALL = 'http://' + sSitePrefix + CLIPMARKS_URL_UNINSTALL; Clipmarks_SettingsXML = document.implementation.createDocument('','elements',null); Clipmarks_GetSettings(); if(Clipmarks_Preferences.get('extensions.clipmarks.firstuse', '1') == '1') { bFirstUse = true; var toolbox = window.document.getElementById('navigator-toolbox'); if (toolbox != null) { var navBar = Clipmarks_getNavigationBar( toolbox ); if (navBar.getAttribute("collapsed") != "true") { Clipmarks_addToToolbar( toolbox, navBar ); } } setTimeout('Clipmarks_set_location(\'' + CLIPMARKS_URL_FIRST_TIME_INSTALL + '\', null, true)', 500); Clipmarks_Preferences.set('extensions.clipmarks.firstuse', '0'); } if(Clipmarks_Preferences.get('extensions.clipmarks.firstuse-2.0', 1) == 1) { Clipmarks_Preferences.set('extensions.clipmarks.firstuse-2.0', 0); Clipmarks_Preferences.set('extensions.clipmarks.use-shortcut-keys', 1); lClipKey = Clipmarks_Preferences.get('extensions.clipmarks.shortcut-key-clip', lClipKey); lBorderKey = Clipmarks_Preferences.get('extensions.clipmarks.shortcut-key-borders', lBorderKey); Clipmarks_Preferences.set('extensions.clipmarks.shortcut-key-clip', lClipKey); Clipmarks_Preferences.set('extensions.clipmarks.shortcut-key-borders', lBorderKey); if (!bFirstUse) { setTimeout('Clipmarks_set_location(\'' + CLIPMARKS_URL_UPGRADE_INSTALL + '\', null, true)', 500); } } if(Clipmarks_Preferences.get('extensions.clipmarks.use-shortcut-keys', 1) == 1) { addEventListener("keypress", Clipmarks_KeyPress, true); } if (Clipmarks_Preferences.get('extensions.clipmarks.use-borders', 1) == 0) { Clipmarks_EnableOrangeLines(true); } gClipmarks_UninstallObserver = new Clipmarks_UninstallObserver(); //gClipmarks_EndDocumentLoadObserver = new Clipmarks_EndDocumentLoadObserver(); Clipmarks_Initialized = true; } } function Clipmarks_UnInit(event) { if (!!gClipmarks_UninstallObserver) { gClipmarks_UninstallObserver.removeObserver(); } if (!!gClipmarks_EndDocumentLoadObserver) { gClipmarks_EndDocumentLoadObserver.removeObserver(); } } function Clipmarks_Help() { var oDocument = getBrowser().contentWindow.document; var oEmbeds = oDocument.getElementsByTagName('EMBED'); for (i = 0; i < oEmbeds.length; i++) { oEmbeds[i].style.visibility = 'hidden'; } var oShadow = oDocument.createElement('DIV'); oShadow.id = 'Clipmarks_ClipModeShadow'; oShadow.style.position = 'absolute'; oShadow.style.top = '0px'; oShadow.style.left = '0px'; oShadow.style.zIndex = '99998'; oShadow.style.backgroundColor = '#000000'; oShadow.style.display = 'block'; oShadow.style.height = '100%'; oShadow.style.width = '100%'; oShadow.style.opacity = '.40'; oDocument.body.appendChild(oShadow); var oFrame = oDocument.createElement('IFRAME'); oFrame.id = 'Clipmarks_ClipModeFrame'; oFrame.src = 'http://content.clipmarks.com/clip_mode_ex.htm?1'; oFrame.style.position = 'absolute'; oFrame.style.top = '25px'; oFrame.style.left = ((oDocument.body.clientWidth / 2) - 340) + 'px'; oFrame.style.width = '670px'; oFrame.style.height = '460px'; oFrame.style.zIndex = '99999'; oFrame.style.border = 'solid 8px #EE9800'; oFrame.style.backgroundColor = '#FFFFFF'; oDocument.body.appendChild(oFrame); oDocument.defaultView.scrollTo(0,0); } function Clipmarks_OffsetLeft(oElement) { var oParent = oElement; var lOffsetLeft = 0; while (oParent && oParent.tagName != 'BODY') { lOffsetLeft += oParent.offsetLeft; oParent = oParent.offsetParent; } return lOffsetLeft; } function Clipmarks_OffsetTop(oElement) { var oParent = oElement; var lOffsetTop = 0; while (oParent && oParent.tagName != 'BODY') { lOffsetTop += oParent.offsetTop; oParent = oParent.offsetParent; } return lOffsetTop; } function Clipmarks_PageMouseDown(event) { if (event.target.tagName == 'IMG') { Clipmarks_CancelMouseUp = true; } Clipmarks_PageLeft = event.pageX; Clipmarks_PageTop = event.pageY; } function Clipmarks_PageMouseUp(event) { if (Clipmarks_ClipMode == 0 || event.target.id.indexOf('Clipmarks_') == 0 || Clipmarks_CancelMouseUp || event.target.tagName == 'HTML') { Clipmarks_CancelClick = false; Clipmarks_CancelMouseUp = false; return; } Clipmarks_RemoveSelectionClipper(event.target.ownerDocument); Clipmarks_CheckForSelection(event); if (!Clipmarks_IsContentSelected) { return; } var oDocument = event.target.ownerDocument; var dvOverlay = oDocument.createElement('IMG'); if (Clipmarks_PageTop > event.pageY) { Clipmarks_PageTop = event.pageY; } if (Clipmarks_PageLeft > event.pageX) { Clipmarks_PageLeft = event.pageX; } dvOverlay.setAttribute('id', 'Clipmarks_SelectionClipper'); dvOverlay.style.position = 'absolute'; dvOverlay.style.zIndex = '99999'; dvOverlay.src = 'http://content0.clipmarks.com/images/disparate-clip.gif?1'; dvOverlay.style.top = (Clipmarks_PageTop - 28) + 'px'; dvOverlay.style.left = (Clipmarks_PageLeft) + 'px'; oDocument.body.appendChild(dvOverlay); dvOverlay.addEventListener('click', Clipmarks_ClipSelection, true); } function Clipmarks_CheckForSelection(e) { var oSelection = null; var oWindow = getBrowser().contentWindow; var bFoundSelection = false; var oDiv = null; var sHTML = ''; bFoundSelection = false; oSelection = oWindow.getSelection(); sHTML = oSelection.toString(); if (sHTML.length > 0) { sHTML = sHTML.replace(/<style.*?>.*?<\/style>/g, ' '); sHTML = sHTML.replace(/<[^>]+>/g, ' '); sHTML = sHTML.replace(/\s+/g, ' '); if (sHTML.length > 2) { bFoundSelection = true; } else { for (i = 0; i < oWindow.frames.length; i++) { oSelection = oWindow.frames[i].getSelection(); sHTML = oSelection.toString(); sHTML = sHTML.replace(/<style.*?>.*?<\/style>/g, ' '); sHTML = sHTML.replace(/<[^>]+>/g, ' '); sHTML = sHTML.replace(/\s+/g, ' '); if (sHTML.length > 2) { bFoundSelection = true; } } } } Clipmarks_IsContentSelected = Clipmarks_CancelClick = bFoundSelection; } function Clipmarks_ContainsElement(container, containee) { var contains = false; while (containee) { if ((contains = container == containee)) { break; } containee = containee.parentNode; } return contains; } function Clipmarks_ShowDoneClipping() { if (!Clipmarks_ClipXML || Clipmarks_ClipXML.documentElement.childNodes.length <= 1) { window.openDialog('chrome://clipmarks/content/please-clip.xul', 'Clipmarks_PleaseClipSomething', 'chrome,centerscreen,dialog,modal'); return; } document.getElementById('imgDoneClipping1').hidden = true; document.getElementById('imgDoneClipping2').hidden = false; setTimeout('Clipmarks_ShowDoneClippingStep2()', 50); Clipmarks_ContextMenuVisible = true; return true; } function Clipmarks_ShowDoneClippingStep2() { var oContextMenu = document.getElementById('Clipmarks-MenuDoneClipping'); oContextMenu.showPopup(document.getElementById('imgDoneClipping2'), -1, -1, 'popup', 'bottomleft', 'topleft'); } function Clipmarks_HideDoneClipping() { document.getElementById('imgDoneClipping2').hidden = true; document.getElementById('imgDoneClipping1').hidden = false; Clipmarks_ContextMenuVisible = false; return true; } function Clipmarks_GetAttribute(oElement, sAttribute, sDefault) { var sReturn = sDefault; if (oElement.getAttribute(sAttribute)) { sReturn = oElement.getAttribute(sAttribute); } return sReturn; } function Clipmarks_GetOuterHTML(oElement, bRoot) { var _emptyTags = { 'img': true, 'br': true, 'input': true, 'meta': true, 'link': true, 'param': true, 'hr': true}; var attrs = oElement.attributes; var str = '<' + oElement.tagName; var i = 0; var sTagName = oElement.tagName.toLowerCase(); var sSRC = ''; if (sTagName == 'iframe' || sTagName == 'script' || Clipmarks_GetAttribute(oElement, 'name', '').indexOf('Clipmarks_') >= 0) { return ''; } if (sTagName == 'form' && Clipmarks_GetAttribute(oElement, 'class', '') == 'yqin' && Clipmarks_GetAttribute(oElement, 'action', '') == 'http://yq.search.yahoo.com/search') { return ''; } for (var i = 0; i < attrs.length; i++) { if (attrs[i].name != 'style' && attrs[i].name.indexOf('on') != 0) { if (sTagName == 'embed') { if (attrs[i].name == 'src') { if (window.content.location.hostname.indexOf('youtube.com') >= 0) { str += ' src="' + attrs[i].value.replace(/\/player(2)?\.swf\?video_id\=([^\&]+)(\&.*)?/m, 'http://www.youtube.com/v/$2') + '"'; } else { str += ' src="' + attrs[i].value.replace(/http\:\/\/(www\.)?youtube\.com\/player(2)?\.swf\?video_id\=([^\&]+)(\&.*)?/m, 'http://www.youtube.com/v/$3') + '"'; } } else if (attrs[i].name == 'type' || attrs[i].name == 'pluginspage') { str += ' ' + attrs[i].name + '="' + attrs[i].value + '"'; } } else { str += ' ' + attrs[i].name + '="' + attrs[i].value + '"'; } } } if (sTagName == 'embed') { str += ' width="95%" height="87%" wmode="transparent" scale="showall" ALIGN="middle"'; } if (_emptyTags[sTagName]) { return str + ' />'; } str += '>'; str += Clipmarks_GetInnerHTML(oElement); str += '</' + oElement.tagName + '>'; return str; } function Clipmarks_GetInnerHTML(oElement) { var str = ''; var i = 0; for (i = 0; i < oElement.childNodes.length; i++) { if (oElement.childNodes[i].nodeType == 1) { str += Clipmarks_GetOuterHTML(oElement.childNodes[i], false); } else if (oElement.childNodes[i].nodeType == 3) { str += oElement.childNodes[i].nodeValue.replace(/\</g, '<').replace(/\>/g, '>'); } } return str; } function Clipmarks_Clip(event) { if (Clipmarks_ClipMode == 0) { Clipmarks_SetClipMode(1); } else { Clipmarks_SetClipMode(0); } } function Clipmarks_IsBlockElement(oElement) { var itscomputedstyle = document.defaultView.getComputedStyle(oElement,''); var bIsBlockElement = false; var i = 0; bIsBlockElement = (oElement.getAttribute('clipmarks-spacer') == 'true'); bIsBlockElement = (bIsBlockElement || (itscomputedstyle.getPropertyValue('display') == 'block' || itscomputedstyle.getPropertyValue('display') == 'table' || oElement.tagName == 'TBODY' || oElement.tagName == 'TR' || oElement.tagName == 'TH' || oElement.tagName == 'TD' || oElement.tagName == 'BR')); if (!bIsBlockElement && oElement.tagName != 'SELECT') { for (i = 0; i < oElement.childNodes.length; i++) { if (oElement.childNodes[i].nodeType == 1 && Clipmarks_IsBlockElement(oElement.childNodes[i])) { return true; } } } if (bIsBlockElement) { bIsBlockElement = (itscomputedstyle.getPropertyValue('float') == 'none'); } return bIsBlockElement; } function Clipmarks_ClipModeOK(event) { var oDocument = event.target.ownerDocument; var fraClipMode = oDocument.defaultView.frameElement; if (!!fraClipMode) { if (oDocument.getElementById('Clipmarks_chkShowAgain').checked) { Clipmarks_Preferences.set('extensions.clipmarks.show-clip-mode-help', 0); } oDocument = fraClipMode.ownerDocument; oDocument.body.removeChild(fraClipMode.previousSibling); oDocument.body.removeChild(fraClipMode); } var oEmbeds = oDocument.getElementsByTagName('EMBED'); for (i = 0; i < oEmbeds.length; i++) { oEmbeds[i].style.visibility = 'visible'; } } function Clipmarks_FixPage(oDocument) { var i = 0; if (oDocument.defaultView.location.pathname.indexOf('clip_mode_ex.htm') >= 0) { var imgOK = oDocument.getElementById('Clipmarks_imgOK'); if (!!imgOK) { imgOK.addEventListener('click', Clipmarks_ClipModeOK, true); } return; } Clipmarks_iFrameCount++; if (Clipmarks_iFrameCount > 30) { return; } for (i = 0; i < oDocument.defaultView.frames.length; i++) { Clipmarks_FixPage(oDocument.defaultView.frames[i].document); } if (oDocument.body && !oDocument.body.hasAttribute('clipmarks_processed')) { oDocument.normalize(); Clipmarks_FixElement(oDocument.body); Clipmarks_AddPageWatch(oDocument); oDocument.body.setAttribute('clipmarks_processed', 'true'); } } function Clipmarks_RemoveMods(oDocument) { if (!oDocument) { return; } var i = 0; var oNames = null; oDocument.removeEventListener('mouseover', Clipmarks_ElementMouseOver, true); oDocument.removeEventListener('mouseout', Clipmarks_ElementMouseOut, true); oDocument.removeEventListener('mouseup', Clipmarks_CheckForSelection, false); if (!!oDocument.getElementById('Clipmarks_ClipModeFrame')) { var oEmbeds = oDocument.getElementsByTagName('EMBED'); for (i = 0; i < oEmbeds.length; i++) { oEmbeds[i].style.visibility = 'visible'; } oDocument.body.removeChild(oDocument.getElementById('Clipmarks_ClipModeFrame').previousSibling); oDocument.body.removeChild(oDocument.getElementById('Clipmarks_ClipModeFrame')); } Clipmarks_iFrameCount++; if (Clipmarks_iFrameCount > 30) { return; } for (i = 0; i < oDocument.defaultView.frames.length; i++) { Clipmarks_RemoveMods(oDocument.defaultView.frames[i].document); } if (oDocument.getElementById(Clipmarks_BorderLeftId)) { oDocument.body.removeChild(oDocument.getElementById(Clipmarks_BorderLeftId)); } if (oDocument.getElementById(Clipmarks_BorderRightId)) { oDocument.body.removeChild(oDocument.getElementById(Clipmarks_BorderRightId)); } if (oDocument.getElementById(Clipmarks_BorderTopId)) { oDocument.body.removeChild(oDocument.getElementById(Clipmarks_BorderTopId)); } if (oDocument.getElementById(Clipmarks_BorderBottomId)) { oDocument.body.removeChild(oDocument.getElementById(Clipmarks_BorderBottomId)); } if (!!oDocument.getElementsByName) { oNames = oDocument.getElementsByName('Clipmarks_ObjectDiv'); for (i = 0; i < oNames.length; i++) { oDocument.body.removeChild(oNames[i]); } oNames = oDocument.getElementsByName('Clipmarks_ObjectDivHeader'); for (i = 0; i < oNames.length; i++) { oDocument.body.removeChild(oNames[i]); } } Clipmarks_RemoveSelectionBounds(oDocument); Clipmarks_RemoveSelectionClipper(oDocument); if (!!oDocument.body) { oDocument.body.removeAttribute('clipmarks_processed'); } } function Clipmarks_RemoveSelectionBounds(oDocument, lClipElementIndex) { if (!oDocument.getElementsByName) { return; } if (!lClipElementIndex) { lClipElementIndex = -1; } var oRange = null; oNames = oDocument.getElementsByName('Clipmarks_SelectionBounds'); for (i = oNames.length - 1; i >= 0; i--) { if (lClipElementIndex == -1 || oNames[i].getAttribute('clip-index') == lClipElementIndex) { if (oNames[i].tagName != 'IMG') { oRange = oDocument.createRange(); oRange.selectNodeContents(oNames[i]); oNames[i].parentNode.insertBefore(oRange.extractContents(), oNames[i]); oRange.detach(); } oNames[i].parentNode.removeChild(oNames[i]); } } } function Clipmarks_Trim(str) { var sx = new String(); sx = str; sx = sx.replace(/^\s*/g, ''); sx = sx.replace(/\s*$/g, ''); return sx; } function Clipmarks_EmbedClip(event) { if (event.target.src == 'http://content0.clipmarks.com/images/video-clipped.gif') { Clipmarks_RemoveEmbed(aryEmbed[event.target.getAttribute('elementIndex')], event.target.getAttribute('elementIndex')); event.target.src = 'http://content0.clipmarks.com/images/video-clip.gif'; } else { Clipmarks_ClipHTMLEmbed(aryEmbed[event.target.getAttribute('elementIndex')], event.target.getAttribute('elementIndex')); event.target.src = 'http://content0.clipmarks.com/images/video-clipped.gif'; } } function Clipmarks_RemoveEmbed(oEmbed, lIndex) { var j = 0; for (j = 1; j < Clipmarks_ClipXML.documentElement.childNodes.length; j++) { if (Clipmarks_ClipXML.documentElement.childNodes[j].getAttribute('embed-index') == lIndex && Clipmarks_ClipXML.documentElement.childNodes[j].getAttribute('type') == 'HTMLEmbed') { Clipmarks_ClipXML.documentElement.removeChild(Clipmarks_ClipXML.documentElement.childNodes[j]); break; } } } function Clipmarks_FixElement(oElement) { var oDocument = oElement.ownerDocument; if (!oDocument.createElement('DIV')) { return; } var brStart = null; var brEnd = null; var oNode = null; var oRange = null; var i = 0; var sDomain = ''; var sSrc = ''; for (i = 0; i < oElement.childNodes.length; i++) { if (oElement.childNodes[i].nodeType == 1) { Clipmarks_FixElement(oElement.childNodes[i]); } } if (CLIPMARKS_ENABLE_VIDEO && oElement.tagName == 'EMBED') { sSrc = oElement.src; for (i = 0; i < Clipmarks_SettingsXML.documentElement.childNodes.length; i++) { sDomain = Clipmarks_SettingsXML.documentElement.childNodes[i].getAttribute('domain'); if ((sSrc.indexOf(sDomain) <= 13 && sSrc.indexOf(sDomain) != -1) || oDocument.defaultView.location.hostname.indexOf(sDomain) >= 0) { var dvOverlay = oDocument.createElement('IMG'); i = aryEmbed.length + 1; aryEmbed[i] = oElement; dvOverlay.setAttribute('name', 'Clipmarks_ObjectDivHeader'); dvOverlay.setAttribute('elementIndex', i); dvOverlay.style.position = 'absolute'; dvOverlay.style.zIndex = '99999'; dvOverlay.style.cursor = 'pointer'; dvOverlay.src = 'http://content0.clipmarks.com/images/video-clip.gif'; dvOverlay.style.top = (Clipmarks_OffsetTop(oElement) - 19) + 'px'; dvOverlay.style.left = (Clipmarks_OffsetLeft(oElement) +(oElement.offsetWidth - 67)) + 'px'; oDocument.body.appendChild(dvOverlay); if (oDocument.location.hostname.indexOf('youtube.com') >= 0 && oDocument.getElementsByName('embed_code').length > 0 && oDocument.getElementsByName('embed_code')[0].value.indexOf('Embedding disabled') >= 0) { dvOverlay.src = 'http://content0.clipmarks.com/images/video-no-clipping.gif'; dvOverlay.addEventListener('click', function(){alert('This video can not be clipped because embedding has been disabled.')}, true); } else { dvOverlay.addEventListener('click', Clipmarks_EmbedClip, true); } break; } } } var oBRs = oElement.getElementsByTagName('BR'); i = 0; while (i < oBRs.length) { brStart = oBRs[i]; if (brStart.parentNode == oElement) { oNode = brStart.nextSibling; while (oNode && oNode.nodeType != 1) { if (oNode.nodeType == 3 && Clipmarks_Trim(oNode.textContent) != '') { oNode = null; break; } oNode = oNode.nextSibling; } if (oNode && oNode.tagName == 'BR') { oNode = brStart.previousSibling; while (oNode) { if (oNode.nodeType == 1 && (Clipmarks_IsBlockElement(oNode) || oNode.tagName == 'BR')) { break; } oNode = oNode.previousSibling; } oRange = oDocument.createRange(); if (oNode) { oRange.setStartAfter(oNode); } else { oRange.setStartBefore(oElement.firstChild); } oRange.setEndBefore(brStart); if (Clipmarks_Trim(oRange.toString()).length > 5) { oNode = oDocument.createElement('DIV'); oNode.name = 'Clipmarks_Spacer'; oRange.surroundContents(oNode); oElement.removeChild(brStart); } } } i++; } } function Clipmarks_IsBadTag(sTag) { return (sTag == 'SCRIPT' || sTag == 'STYLE' || sTag == 'NOSCRIPT'); } function Clipmarks_SetClipMode(lMode) { var i = 0; if (lMode == 1) { Clipmarks_ClipElementIndex = 0; Clipmarks_ClipMode = 1; document.getElementById('Clipmarks-TB-Clip').checked = true; document.getElementById('Clipmarks-TB-Clip').tooltipText = 'exit clip mode'; Clipmarks_CheckForSelection(); for (i = 0; i < window.frames.length; i++) { Clipmarks_ShowModeStatus(window.frames[i].document); } Clipmarks_CalcPopLimit(); window.document.getElementById('Clipmarks-SaveBar').hidden = false; setTimeout('Clipmarks_FixAllPages()', 50); } else { setTimeout('window.document.getElementById(\'Clipmarks-SaveBar\').hidden = true', 250); Clipmarks_ClipMode = 0; Clipmarks_ClearOverlays(); document.getElementById('Clipmarks-TB-Clip').checked = false; document.getElementById('Clipmarks-TB-Clip').tooltipText = 'enter clip mode'; Clipmarks_iFrameCount = 0; for (i = 0; i < window.frames.length; i++) { if (window.frames[i].name != 'Clipmarks_SaveOverlimitDialog') { Clipmarks_RemoveMods(window.frames[i].document); } } } } function Clipmarks_FixAllPages() { for (i = 0; i < window.frames.length; i++) { Clipmarks_iFrameCount = 0; Clipmarks_FixPage(window.frames[i].document); } for (i = 0; i < window.frames.length; i++) { Clipmarks_HideModeStatus(window.frames[i].document); } } function Clipmarks_ShowModeStatus(oDocument) { return; HideScrollbars(oDocument); var oImage = oDocument.createElement('IMG'); oImage.id = 'imgClipmarksStatusImage'; oImage.src = 'chrome://clipmarks/skin/entering-clip-mode.gif'; oImage.style.position = 'absolute'; oImage.style.top = '0px'; oImage.style.left = '0px'; oImage.style.zIndex = '9998'; oImage.style.opacity = '0.92'; oImage.style.Mozopacity = '0.92'; oDocument.body.appendChild(oImage); oDocument.body.setAttribute('previous-overflow', oDocument.body.style.overflow); oDocument.body.style.overflow = 'hidden'; } function Clipmarks_HideModeStatus(oDocument) { return; ShowScrollbars(oDocument); oDocument.body.removeChild(oDocument.getElementById('imgClipmarksStatusImage')); oDocument.body.style.overflow = oDocument.body.getAttribute('previous-overflow'); } function HideScrollbars(oDocument) { var is_mac = false; if (is_mac) { } } function ShowScrollbars(oDocument) { var is_mac = false; if (is_mac) { } } function Clipmarks_Tag(event, bPrint, bEmail, bBlog) { document.getElementById('Clipmarks-MenuDoneClipping').hidePopup(); Clipmarks_PrintClicked = (bPrint == true); Clipmarks_EmailClicked = (bEmail == true); Clipmarks_BlogClicked = (bBlog == true); if (!bPrint && !bEmail && Clipmarks_CharCount > 1000) { if (bBlog) { window.openDialog('chrome://clipmarks/content/blog-overlimit.xul', 'Clipmarks_BlogOverlimitDialog', 'chrome,centerscreen,dialog,modal'); } else { window.openDialog('chrome://clipmarks/content/save-overlimit.xul', 'Clipmarks_SaveOverlimitDialog', 'chrome,centerscreen,dialog,modal'); } return; } Clipmarks_Save(); } function Clipmarks_Save() { Clipmarks_XMLHTTP = new XMLHttpRequest(); var oSerializer = new XMLSerializer(); var sXML = new XMLSerializer().serializeToString(Clipmarks_ClipXML); Clipmarks_XMLHTTP.open('POST', CLIPMARKS_URL_SAVE_CLIP, true); Clipmarks_XMLHTTP.onreadystatechange = Clipmarks_SaveStateChange; Clipmarks_XMLHTTP.send(sXML); Clipmarks_SetClipMode(0); } function Clipmarks_SaveStateChange() { if (Clipmarks_XMLHTTP.readyState != 4) { return; } if (Clipmarks_PrintClicked) { window.open(CLIPMARKS_URL_PRINT_CLIP + '?direct=true&c=' + Clipmarks_XMLHTTP.responseXML.documentElement.textContent, 'Clipmarks_PrintClip', 'width=759,height=555,resizable=yes'); } else if (Clipmarks_EmailClicked) { window.open(CLIPMARKS_URL_EMAIL_CLIP + '?direct=true&clipmark=' + Clipmarks_XMLHTTP.responseXML.documentElement.textContent, 'Clipmarks_EmailClip', 'width=759,height=555,resizable=yes'); } else if (Clipmarks_BlogClicked) { window.open(CLIPMARKS_URL_BLOG_CLIP + '?direct=true&c=' + Clipmarks_XMLHTTP.responseXML.documentElement.textContent, 'Clipmarks_BlogClip', 'width=759,height=555,resizable=yes'); } else { window.open(CLIPMARKS_URL_EDIT_CLIP + '?clipping=true&clip_guid=' + Clipmarks_XMLHTTP.responseXML.documentElement.textContent, 'Clipmarks_EditClip', 'width=759,height=555,resizable=yes'); } } function Clipmarks_InitXML() { Clipmarks_ClipXML = document.implementation.createDocument('','elements',null); Clipmarks_ClipXML.documentElement.setAttribute('version', CLIPMARKS_VERSION); var oClient = Clipmarks_ClipXML.createElement('client'); oClient.appendChild(Clipmarks_ClipXML.createElement('userAgent')).textContent = window.navigator.userAgent; Clipmarks_ClipXML.documentElement.appendChild(oClient); } function Clipmarks_AddPageWatch(oDocument) { if (!oDocument.createElement('DIV')) { return; } if (Clipmarks_ClipXML == null) { Clipmarks_InitXML(); } if (oDocument.getElementById(Clipmarks_BorderLeftId)) { return; } var oBorderDiv; oBorderDiv = oDocument.createElement('DIV'); oBorderDiv.id = Clipmarks_BorderLeftId; oBorderDiv.style.position = 'absolute'; oBorderDiv.style.width = '0px'; oBorderDiv.style.border = 'orange 2px solid'; oBorderDiv.style.display = 'none'; oBorderDiv.style.zIndex = '99998'; oBorderDiv.style.padding = '0px'; oBorderDiv.style.margin = '0px'; oDocument.body.appendChild(oBorderDiv); oBorderDiv = oDocument.createElement('DIV'); oBorderDiv.id = Clipmarks_BorderRightId; oBorderDiv.style.position = 'absolute'; oBorderDiv.style.width = '0px'; oBorderDiv.style.border = 'orange 2px solid'; oBorderDiv.style.display = 'none'; oBorderDiv.style.zIndex = '99998'; oBorderDiv.style.padding = '0px'; oBorderDiv.style.margin = '0px'; oDocument.body.appendChild(oBorderDiv); oBorderDiv = oDocument.createElement('DIV'); oBorderDiv.id = Clipmarks_BorderTopId; oBorderDiv.style.position = 'absolute'; oBorderDiv.style.height = '0px'; oBorderDiv.style.border = 'orange 2px solid'; oBorderDiv.style.display = 'none'; oBorderDiv.style.zIndex = '99998'; oBorderDiv.style.padding = '0px'; oBorderDiv.style.margin = '0px'; oDocument.body.appendChild(oBorderDiv); oBorderDiv = oDocument.createElement('DIV'); oBorderDiv.id = Clipmarks_BorderBottomId; oBorderDiv.style.position = 'absolute'; oBorderDiv.style.height = '0px'; oBorderDiv.style.border = 'orange 2px solid'; oBorderDiv.style.display = 'none'; oBorderDiv.style.zIndex = '99998'; oBorderDiv.style.padding = '0px'; oBorderDiv.style.margin = '0px'; oDocument.body.appendChild(oBorderDiv); oDocument.addEventListener('mouseover', Clipmarks_ElementMouseOver, true); oDocument.addEventListener('mouseout', Clipmarks_ElementMouseOut, true); oDocument.addEventListener('mousedown', Clipmarks_PageMouseDown, true); oDocument.addEventListener('mouseup', Clipmarks_PageMouseUp, true); } function PrintToLog(oDocument, sText) { return; var oPrintLog = oDocument.getElementById('dvPrintLog'); if (!oPrintLog) { var oLineDiv = null; oLineDiv = oDocument.createElement('DIV'); oLineDiv.id = 'dvPrintLog'; oLineDiv.style.position = 'absolute'; oLineDiv.style.border = 'green 2px solid'; oLineDiv.style.backgroundColor = '#FFFFFF'; oLineDiv.align = 'left'; oLineDiv.style.height = '600px'; oLineDiv.style.width = '500px'; oLineDiv.style.top = '10px'; oLineDiv.style.left = '750px'; oLineDiv.style.top = '0px'; oLineDiv.style.display = 'block'; oLineDiv.style.zIndex = '99998'; oLineDiv.style.padding = '0px'; oLineDiv.style.margin = '0px'; //oLineDiv.style.float = 'right'; oLineDiv.style.overflow = 'auto'; oDocument.body.appendChild(oLineDiv); oPrintLog = oLineDiv; } oPrintLog.innerHTML = sText + '<br /><br />' + oPrintLog.innerHTML; } function Clipmarks_CheckForOverlappingRect(oRect, oElement) { var oDocument = oElement.ownerDocument; var oInsideElement = oElement.previousSibling; var oInsideRect = null; var oReturn = null; if (!oInsideElement) { return false; } if (oInsideElement.nodeType != 1) { return Clipmarks_CheckForOverlappingRect(oRect, oInsideElement); } Clipmarks_SiblingsChecked++; if (Clipmarks_SiblingsChecked > 20) { return false; } oInsideRect = Clipmarks_GetRect(oDocument, oInsideElement); if ((oInsideRect.top < oRect.bottom && oInsideRect.bottom > oRect.top) && (oInsideRect.left < oRect.right && oInsideRect.right > oRect.left)) { return oInsideRect; } oReturn = Clipmarks_CheckForOverlappingRect(oRect, oInsideElement); if (oReturn) { return oReturn; } for (i = 0; i < oInsideElement.childNodes.length; i++) { if (oInsideElement.childNodes[i].nodeType == 1) { oInsideRect = Clipmarks_GetRect(oDocument, oInsideElement.childNodes[i]); if ((oInsideRect.top < oRect.bottom && oInsideRect.bottom > oRect.top) && (oInsideRect.left < oRect.right && oInsideRect.right > oRect.left)) { return oInsideRect; } } } return false; } function Clipmarks_ShowBorderDiv(oElement) { if (!oElement) { return; } if (Clipmarks_ActiveElement != null) { Clipmarks_HideBorderDiv(Clipmarks_ActiveElement); Clipmarks_ActiveElement = null; } var oDocument = oElement.ownerDocument; var oRect = Clipmarks_GetRect(oDocument, oElement); if (oElement.tagName != 'IMG') { if (((oRect.right - oRect.left) > 250 && (oRect.bottom - oRect.top) > 500) || ((oRect.right - oRect.left) > 500 && (oRect.bottom - oRect.top) > 250)) { return; } } Clipmarks_ActiveElement = oElement; var oInsideElement = null; var oInsideRect = null; var bIsSquare = false; var bBoxOnLeft = false; if (oElement.tagName == 'IMG') { bIsSquare = true; } else { oInsideElement = oElement.previousSibling; Clipmarks_SiblingsChecked = 0; oInsideRect = Clipmarks_CheckForOverlappingRect(oRect, oElement); if (!oInsideRect) { if (oDocument.location.href.indexOf('forbes.com') > 0 && oElement.parentNode && oElement.parentNode.previousSibling) { oInsideRect = Clipmarks_CheckForOverlappingRect(oRect, oElement.parentNode.previousSibling); } else if (oElement.parentNode) { oInsideRect = Clipmarks_CheckForOverlappingRect(oRect, oElement.parentNode); if (!oInsideRect && oElement.parentNode.parentNode) { oInsideRect = Clipmarks_CheckForOverlappingRect(oRect, oElement.parentNode.parentNode); } } } if (!oInsideRect) { bIsSquare = true; } else { if (oInsideRect.left - 5 < oRect.left) { bBoxOnLeft = true; } if (oInsideRect.bottom + 5 > oRect.bottom) { bIsSquare = true; } } } if (oInsideRect && bIsSquare) { if (bBoxOnLeft) { oRect.left = oInsideRect.right; } else { oRect.right = oInsideRect.left; } } if (bIsSquare) { Clipmarks_MakeLine(oDocument, oRect.top - 4, oRect.left - 4, (oRect.right - oRect.left) + 8, false); Clipmarks_MakeLine(oDocument, oRect.top, oRect.left - 4, oRect.bottom - oRect.top, true); Clipmarks_MakeLine(oDocument, oRect.top, oRect.right, oRect.bottom - oRect.top, true); Clipmarks_MakeLine(oDocument, oRect.bottom, oRect.left - 4, (oRect.right - oRect.left) + 8, false); } else { if (bBoxOnLeft) { Clipmarks_MakeLine(oDocument, oRect.top - 4, oInsideRect.right - 4, (oRect.right - oInsideRect.right) + 8, false); Clipmarks_MakeLine(oDocument, oRect.top, oInsideRect.right - 4, oInsideRect.bottom - oRect.top, true); Clipmarks_MakeLine(oDocument, oInsideRect.bottom - 4, oRect.left - 4, (oInsideRect.right - oRect.left) + 4, false); Clipmarks_MakeLine(oDocument, oInsideRect.bottom, oRect.left - 4, oRect.bottom - oInsideRect.bottom, true); Clipmarks_MakeLine(oDocument, oRect.top, oRect.right, oRect.bottom - oRect.top, true); Clipmarks_MakeLine(oDocument, oRect.bottom, oRect.left - 4, (oRect.right - oRect.left) + 8, false); } else { Clipmarks_MakeLine(oDocument, oRect.top -4, oRect.left - 4, (oInsideRect.left - oRect.left) + 8, false); Clipmarks_MakeLine(oDocument, oRect.top, oRect.left - 4, oRect.bottom - oRect.top, true); Clipmarks_MakeLine(oDocument, oInsideRect.bottom - 4, oInsideRect.left, (oRect.right - oInsideRect.left) + 4, false); Clipmarks_MakeLine(oDocument, oInsideRect.bottom, oRect.right, oRect.bottom - oInsideRect.bottom, true); Clipmarks_MakeLine(oDocument, oRect.top, oInsideRect.left, oInsideRect.bottom - oRect.top, true); Clipmarks_MakeLine(oDocument, oRect.bottom, oRect.left - 4, (oRect.right - oRect.left) + 8, false); } } } function Clipmarks_GetRect(oDocument, oElement) { var coords = { left: 0, top: 0, right: 0, bottom: 0 }; var oRect = null; if (oElement.getBoundingClientRect) { oRect = oElement.getBoundingClientRect(); coords.left = Clipmarks_OffsetLeft(oElement); coords.right = (oRect.right - oRect.left) + coords.left; coords.top = Clipmarks_OffsetTop(oElement); coords.bottom = (oRect.bottom - oRect.top) + coords.top; } else if (oDocument.getBoxObjectFor) { oRect = oDocument.getBoxObjectFor(oElement); coords.left = oRect.x; coords.right = oRect.x + oRect.width; coords.top = oRect.y; coords.bottom = oRect.y + oRect.height; } else { coords.right = oElement.offsetWidth; coords.bottom = oElement.offsetHeight; coords.left = Clipmarks_OffsetLeft(oElement); coords.top = Clipmarks_OffsetTop(oElement); coords.right += coords.left; coords.bottom += coords.top; } return coords; } function Clipmarks_MakeLine(oDocument, lTop, lLeft, lLength, bVertical, sName) { var oLineDiv = null; if (!sName) { sName = 'Clipmarks_LineElement'; } oLineDiv = oDocument.createElement('DIV'); oLineDiv.setAttribute('name', sName); oLineDiv.style.position = 'absolute'; oLineDiv.style.border = 'orange 2px solid'; oLineDiv.align = 'left'; if (bVertical) { oLineDiv.style.height = lLength + 'px'; oLineDiv.style.width = '0px'; oLineDiv.style.borderWidth = '0px 2px 0px 2px'; } else { oLineDiv.style.height = '0px'; oLineDiv.style.width = lLength + 'px'; oLineDiv.style.borderWidth = '2px 0px 2px 0px'; } oLineDiv.style.display = 'block'; oLineDiv.style.zIndex = '99998'; oLineDiv.style.padding = '0px'; oLineDiv.style.margin = '0px'; oLineDiv.style.left = (lLeft) + 'px'; oLineDiv.style.top = (lTop) + 'px'; oDocument.body.appendChild(oLineDiv); } function Clipmarks_HideBorderDiv(oElement) { var oDocument = oElement.ownerDocument; var oBorderDivs = oDocument.getElementsByName('Clipmarks_LineElement'); for (i = oBorderDivs.length - 1; i >= 0; i--) { oDocument.body.removeChild(oBorderDivs[i]); } } function getAccessibleFor(domNode) { var accRetrieval = null; try { accRetrieval = Components.classes["@mozilla.org/accessibleRetrieval;1"].createInstance(Components.interfaces.nsIAccessibleRetrieval); } catch (ex) { dump ("\nError getting accessibility retrieval service\n" + ex);} if (!accRetrieval) { alert("No accessible retrieval"); return null; } try { return accRetrieval.getAccessibleFor(domNode); } catch(ex) { } return null; } function Clipmarks_ElementMouseOver(event) { if (Clipmarks_ClipMode == 0 || Clipmarks_ContextMenuVisible || !Clipmarks_UseBorders) { return true; } if ( event.target.tagName == 'BODY' || event.target.tagName == 'HTML' || event.target.tagName == 'FRAME' || event.target.tagName == 'FRAMESET' || event.target.tagName == 'IFRAME' || event.target.tagName == 'A' || event.target.tagName == 'INPUT' || event.target.tagName == 'BUTTON' || event.target.tagName == 'EMBED' || event.target.id == Clipmarks_BorderLeftId || event.target.id == Clipmarks_BorderRightId || event.target.id == Clipmarks_BorderTopId || event.target.id == Clipmarks_BorderBottomId || event.target.id == 'Clipmarks_LineElement' || event.target.id == 'Clipmarks_HighlightDiv' || event.target.id == 'Clipmarks_HighlightDivChild' || event.target.id == 'Clipmarks_SelectionClipper' || Clipmarks_GetAttribute(event.target, 'name') == 'Clipmarks_SelectionBounds' || event.target.id == 'Clipmarks_ClipModeShadow' || event.target.id == 'Clipmarks_ClipModeFrame' || Clipmarks_GetAttribute(event.target, 'name') == 'Clipmarks_ObjectDiv' || Clipmarks_GetAttribute(event.target, 'name') == 'Clipmarks_ObjectDivHeader' || (event.target.offsetHeight < 10 && event.target.offsetWidth < 10)) { return true; } var bIsAnchor = false; var oParent = null; var i = 0; if (event.target.tagName != 'IMG') { oParent = event.target; for (i = 0; i < 3; i++ ) { if (oParent.tagName == 'A' || oParent.tagName == 'BODY') { break; } oParent = oParent.parentNode; } if (oParent.tagName == 'A') { bIsAnchor = true; return true; } } Clipmarks_ElementIsColumn = false; Clipmarks_ShowBorderDiv(event.target); event.target.addEventListener('click', Clipmarks_ElementClick, true); event.target.addEventListener('contextmenu', Clipmarks_ElementContextMenu, true); return true; } function Clipmarks_ElementMouseOut(event) { if (!Clipmarks_ActiveElement || Clipmarks_ContextMenuVisible) { return true; } event.target.removeEventListener('click', Clipmarks_ElementClick, true); event.target.removeEventListener('contextmenu', Clipmarks_ElementContextMenu, true); Clipmarks_HideBorderDiv(Clipmarks_ActiveElement); Clipmarks_ActiveElement = null; return true; } function Clipmarks_ElementContextMenu(event) { if (Clipmarks_ClipMode == 0) { return true; } event.cancelBubble = true; event.preventDefault(); event.stopPropagation(); return false; } function Clipmarks_ElementClick(event) { if (Clipmarks_ActiveElement.tagName == 'EMBED' || Clipmarks_CancelClick || (event && Clipmarks_GetAttribute(event.target, 'name') == 'Clipmarks_SelectionBounds')) { Clipmarks_CancelClick = false; if (event) { event.cancelBubble = true; event.preventDefault(); event.stopPropagation(); } return false; //return true; } var oDocument = Clipmarks_ActiveElement.ownerDocument; var oHighlightDiv; var oHighlightDivChild; var oElement = Clipmarks_ActiveElement; var oRect = Clipmarks_GetRect(oDocument, oElement); var oInsideElement = null; var oInsideRect = null; var bIsSquare = false; var bBoxOnLeft = false; var lLeft = 0; var lTop = 0; var lWidth = 0; var lHeight = 0; var lClipElementIndex = Clipmarks_ClipElementIndex; Clipmarks_ClipElementIndex++; for (var i = Clipmarks_ClipElements.length - 1; i >= 0; i--) { if (Clipmarks_ContainsElement(Clipmarks_ActiveElement, Clipmarks_ClipElements[i])) { Clipmarks_RemoveElement(Clipmarks_ClipOverlays[i]); } } Clipmarks_HideBorderDiv(Clipmarks_ActiveElement); if (Clipmarks_ActiveElement.tagName == 'IMG') { Clipmarks_ClipHTMLImg(Clipmarks_ActiveElement); } else if (Clipmarks_ActiveElement.tagName == 'EMBED') { Clipmarks_ClipHTMLEmbed(Clipmarks_ActiveElement); } else { Clipmarks_ClipHTMLElement(Clipmarks_ActiveElement, Clipmarks_ElementIsColumn); } Clipmarks_ClipXML.documentElement.lastChild.setAttribute('clip-index', lClipElementIndex); if (oElement.tagName == 'IMG') { bIsSquare = true; } else { oInsideElement = oElement.previousSibling; Clipmarks_SiblingsChecked = 0; oInsideRect = Clipmarks_CheckForOverlappingRect(oRect, oElement); if (!oInsideRect) { if (oDocument.location.href.indexOf('forbes.com') > 0 && oElement.parentNode && oElement.parentNode.previousSibling) { oInsideRect = Clipmarks_CheckForOverlappingRect(oRect, oElement.parentNode.previousSibling); } else if (oElement.parentNode) { oInsideRect = Clipmarks_CheckForOverlappingRect(oRect, oElement.parentNode); if (!oInsideRect && oElement.parentNode.parentNode) { oInsideRect = Clipmarks_CheckForOverlappingRect(oRect, oElement.parentNode.parentNode); } } } if (!oInsideRect) { bIsSquare = true; } else { if (oInsideRect.left - 5 < oRect.left) { bBoxOnLeft = true; } if (oInsideRect.bottom + 5 > oRect.bottom) { bIsSquare = true; } } } if (oInsideRect && bIsSquare) { if (bBoxOnLeft) { oRect.left = oInsideRect.right; } else { oRect.right = oInsideRect.left; } } lTop = oRect.top; lHeight = (oRect.bottom - oRect.top) + 2; if (oRect.top != 0) { lTop += -2; lHeight += 2; } if (bIsSquare) { lLeft = oRect.left; lWidth = (oRect.right - oRect.left) + 2; if (oRect.left != 0) { lLeft += -2; lWidth += 2; } } else { if (bBoxOnLeft) { lLeft = oInsideRect.right - 2; lWidth = (oRect.right - oInsideRect.right) + 4; Clipmarks_MakeLine(oDocument, oRect.top - 4, oInsideRect.right - 4, (oRect.right - oInsideRect.right) + 8, false, 'Clipmarks_SupportNode' + lClipElementIndex); Clipmarks_MakeLine(oDocument, oRect.top, oInsideRect.right - 4, oInsideRect.bottom - oRect.top, true, 'Clipmarks_SupportNode' + lClipElementIndex); Clipmarks_MakeLine(oDocument, oInsideRect.bottom - 4, oRect.left - 4, (oInsideRect.right - oRect.left) + 4, false, 'Clipmarks_SupportNode' + lClipElementIndex); Clipmarks_MakeLine(oDocument, oInsideRect.bottom, oRect.left - 4, oRect.bottom - oInsideRect.bottom, true, 'Clipmarks_SupportNode' + lClipElementIndex); Clipmarks_MakeLine(oDocument, oRect.top, oRect.right, oRect.bottom - oRect.top, true, 'Clipmarks_SupportNode' + lClipElementIndex); Clipmarks_MakeLine(oDocument, oRect.bottom, oRect.left - 4, (oRect.right - oRect.left) + 8, false, 'Clipmarks_SupportNode' + lClipElementIndex); } else { lLeft = oRect.left; lWidth = (oInsideRect.left - oRect.left) + 2; if (oRect.left != 0) { lLeft += -2; lWidth += 2; } Clipmarks_MakeLine(oDocument, oRect.top -4, oRect.left - 4, (oInsideRect.left - oRect.left) + 8, false, 'Clipmarks_SupportNode' + lClipElementIndex); Clipmarks_MakeLine(oDocument, oRect.top, oRect.left - 4, oRect.bottom - oRect.top, true, 'Clipmarks_SupportNode' + lClipElementIndex); Clipmarks_MakeLine(oDocument, oInsideRect.bottom - 4, oInsideRect.left, (oRect.right - oInsideRect.left) + 4, false, 'Clipmarks_SupportNode' + lClipElementIndex); Clipmarks_MakeLine(oDocument, oInsideRect.bottom, oRect.right, oRect.bottom - oInsideRect.bottom, true, 'Clipmarks_SupportNode' + lClipElementIndex); Clipmarks_MakeLine(oDocument, oRect.top, oInsideRect.left, oInsideRect.bottom - oRect.top, true, 'Clipmarks_SupportNode' + lClipElementIndex); Clipmarks_MakeLine(oDocument, oRect.bottom, oRect.left - 4, (oRect.right - oRect.left) + 8, false, 'Clipmarks_SupportNode' + lClipElementIndex); } } oHighlightDiv = oDocument.createElement('DIV'); oHighlightDiv.id = 'Clipmarks_HighlightDiv'; oHighlightDiv.align = 'left'; oHighlightDiv.style.position = 'absolute'; if (bIsSquare) { oHighlightDiv.style.border = '#FF9900 2px solid'; } oHighlightDiv.style.left = lLeft + 'px'; oHighlightDiv.style.top = lTop + 'px'; oHighlightDiv.style.width = lWidth + 'px'; oHighlightDiv.style.height = lHeight + 'px'; oHighlightDiv.style.zIndex = '99998'; oHighlightDiv.style.padding = '0px'; oHighlightDiv.style.margin = '0px'; oHighlightDiv.style.textAlign = 'left'; oHighlightDiv.addEventListener('click', Clipmarks_HighlightElementClick, true); oHighlightDiv.setAttribute('clip-index', lClipElementIndex); oDocument.body.appendChild(oHighlightDiv); oHighlightDivChild = oDocument.createElement('DIV'); oHighlightDivChild.id = 'Clipmarks_HighlightDivChild'; oHighlightDivChild.style.position = 'absolute'; oHighlightDivChild.style.width = '100%'; oHighlightDivChild.style.height = '100%'; oHighlightDivChild.style.lineHeight = (lHeight - 4) + 'px'; oHighlightDivChild.align = 'center'; oHighlightDivChild.verticalAlign = 'middle'; oHighlightDivChild.style.padding = '0px'; oHighlightDivChild.style.margin = '0px'; oHighlightDivChild.style.textAlign = 'center'; if ((lHeight * 3.94) < lWidth) { if (lHeight >= 72) { oHighlightDivChild.innerHTML = ' <img style="vertical-align:middle;display:inline;" src="http://content0.clipmarks.com/images/clipped.png" width="272" height="69" id="Clipmarks_HighlightDivChild" />'; } else { oHighlightDivChild.innerHTML = ' <img style="vertical-align:middle;display:inline;" src="http://content0.clipmarks.com/images/clipped.png" height="' + parseInt(lHeight * .9) + '" id="Clipmarks_HighlightDivChild" />'; } } else { if (lWidth >= 278) { oHighlightDivChild.innerHTML = ' <img style="vertical-align:middle;display:inline;" src="http://content0.clipmarks.com/images/clipped.png" width="272" height="69" id="Clipmarks_HighlightDivChild" />'; } else { oHighlightDivChild.innerHTML = ' <img style="vertical-align:middle;display:inline;" src="http://content0.clipmarks.com/images/clipped.png" width="' + parseInt(lWidth * .9) + '" id="Clipmarks_HighlightDivChild" />'; } } oHighlightDivChild.style.backgroundColor = '#4DC136'; oHighlightDivChild.style.opacity = '0.85'; oHighlightDivChild.style.Mozopacity = '0.85'; oHighlightDiv.appendChild(oHighlightDivChild); Clipmarks_ClipElements[Clipmarks_ClipElements.length] = Clipmarks_ActiveElement; Clipmarks_ClipOverlays[Clipmarks_ClipOverlays.length] = oHighlightDiv; if (!bIsSquare) { lTop = oInsideRect.bottom - 2; lHeight = (oRect.bottom - oInsideRect.bottom) + 4; if (bBoxOnLeft) { lLeft = oRect.left - 2; lWidth = (oInsideRect.right - oRect.left); } else { lLeft = oInsideRect.left + 2; lWidth = oRect.right - oInsideRect.left; } oHighlightDiv = oDocument.createElement('DIV'); oHighlightDiv.setAttribute('name', 'Clipmarks_SupportNode' + lClipElementIndex); oHighlightDiv.align = 'left'; oHighlightDiv.style.position = 'absolute'; oHighlightDiv.style.left = lLeft + 'px'; oHighlightDiv.style.top = lTop + 'px'; oHighlightDiv.style.width = lWidth + 'px'; oHighlightDiv.style.height = lHeight + 'px'; oHighlightDiv.style.zIndex = '99998'; oHighlightDiv.style.padding = '0px'; oHighlightDiv.style.margin = '0px'; oHighlightDiv.style.textAlign = 'left'; oHighlightDiv.addEventListener('click', Clipmarks_HighlightElementClick, true); oHighlightDiv.setAttribute('clip-index', lClipElementIndex); oDocument.body.appendChild(oHighlightDiv); oHighlightDivChild = oDocument.createElement('DIV'); oHighlightDivChild.id = 'Clipmarks_HighlightDivChild'; oHighlightDivChild.style.position = 'absolute'; oHighlightDivChild.style.width = '100%'; oHighlightDivChild.style.height = '100%'; oHighlightDivChild.style.padding = '0px'; oHighlightDivChild.style.margin = '0px'; oHighlightDivChild.style.backgroundColor = '#4DC136'; oHighlightDivChild.style.opacity = '0.85'; oHighlightDivChild.style.Mozopacity = '0.85'; oHighlightDiv.appendChild(oHighlightDivChild); } oHighlightDivChild = null; oHighlightDiv = null; Clipmarks_ActiveElement = null; if (event) { event.cancelBubble = true; event.preventDefault(); event.stopPropagation(); } Clipmarks_CalcPopLimit(); return false; } function Clipmarks_CalcPopLimit() { var i = 0; var sHTML = new String(); var lTotalChars = 0; var lChars = 0; var j = 0; var oFrameXML = null; if (!!Clipmarks_ClipXML) { for (i = 0; i < Clipmarks_ClipXML.documentElement.childNodes.length; i++) { oFrameXML = Clipmarks_ClipXML.documentElement.childNodes[i]; if (oFrameXML.getAttribute('type') == 'IHTMLTxtRange') { if (oFrameXML.childNodes[0].nodeName == 'permalink') { sHTML = oFrameXML.childNodes[2].childNodes[0].nodeValue; } else { sHTML = oFrameXML.childNodes[1].childNodes[0].nodeValue; } sHTML = sHTML.replace(/<style.*?>.*?<\/style>/g, ' '); sHTML = sHTML.replace(/<[^>]+>/g, ' '); sHTML = sHTML.replace(/\s+/g, ' '); sHTML = Clipmarks_Trim(sHTML); lChars = sHTML.length; lTotalChars += lChars; window.document.getElementById('Clipmarks_CharacterCount').value = lTotalChars; if ((1000 - lTotalChars) < 0) { window.document.getElementById('Clipmarks_CharactersRemaining').value = (lTotalChars - 1000); window.document.getElementById('Clipmarks_CharactersRemainingText').value = ' OVER '; window.content.status = lTotalChars + ' characters clipped, ' + (lTotalChars - 1000) + ' OVER publishing limit.'; } else { window.document.getElementById('Clipmarks_CharactersRemaining').value = (1000 - lTotalChars); window.document.getElementById('Clipmarks_CharactersRemainingText').value = ' to '; window.content.status = lTotalChars + ' characters clipped, ' + (1000 - lTotalChars) + ' to publishing limit.'; } } } } if (lTotalChars == 0) { window.document.getElementById('Clipmarks_CharacterCount').value = 0; window.document.getElementById('Clipmarks_CharactersRemaining').value = 1000; window.document.getElementById('Clipmarks_CharactersRemainingText').value = ' to '; window.content.status = '0 characters clipped, 1000 remaining.'; } /* if (lTotalChars > 1000) { window.document.getElementById('Clipmarks_BlogClip').disabled = true; window.document.getElementById('Clipmarks_BlogClip').src = 'chrome://clipmarks/skin/save-bar-blog-inactive.png'; window.document.getElementById('Clipmarks_BlogClip').tooltipText = 'you have exceeded the Clip-to-Blog limit of 1,000 characters'; } else { window.document.getElementById('Clipmarks_BlogClip').disabled = false; window.document.getElementById('Clipmarks_BlogClip').src = 'chrome://clipmarks/skin/save-bar-blog-active.png'; window.document.getElementById('Clipmarks_BlogClip').tooltipText = 'post to your blog'; } */ Clipmarks_CharCount = lTotalChars; } function Clipmarks_ClipHTMLImg(oImage) { var oSourceDocument = oImage.ownerDocument; var oFrameElement = Clipmarks_ClipXML.createElement('frame'); var oImageElement = Clipmarks_ClipXML.createElement('image'); var oAttribute; oFrameElement.setAttribute('type', 'HTMLImg'); oFrameElement.setAttribute('background-color', oSourceDocument.bgColor); Clipmarks_DetectPermalink(oFrameElement, oImage); Clipmarks_BuildSourceNode(oFrameElement, oSourceDocument); oImageElement.appendChild(Clipmarks_ClipXML.createElement('src')).textContent = oImage.src; oImageElement.appendChild(Clipmarks_ClipXML.createElement('alt')).textContent = oImage.alt; oImageElement.appendChild(Clipmarks_ClipXML.createElement('height')).textContent = oImage.height; oImageElement.appendChild(Clipmarks_ClipXML.createElement('width')).textContent = oImage.width; oFrameElement.appendChild(oImageElement); oImageElement = null; Clipmarks_ClipXML.documentElement.appendChild(oFrameElement); oFrameElement = null; } function Clipmarks_ClipHTMLEmbed(oEmbed, lIndex) { var sSrc = ''; var sType = ''; var sFlashVars = ''; var oSourceDocument = oEmbed.ownerDocument; var oInputs = oSourceDocument.getElementsByTagName('INPUT'); var oFrameElement = Clipmarks_ClipXML.createElement('frame'); var oImageElement = Clipmarks_ClipXML.createElement('embed'); var oAttribute; var sAlert = ''; var bEmbedFound = false; oFrameElement.setAttribute('type', 'HTMLEmbed'); oFrameElement.setAttribute('background-color', oSourceDocument.bgColor); oFrameElement.setAttribute('embed-index', lIndex); Clipmarks_DetectPermalink(oFrameElement, oEmbed); Clipmarks_BuildSourceNode(oFrameElement, oSourceDocument); for (i = 0; i < oInputs.length; i++) { if (oInputs[i].type == 'text') { sSrc = oInputs[i].value.replace(/.*\<embed[^\<]+src\=([\"\'])([^\"\']*)\1.*/mig, '$2'); sAlert += i + ' - ' + sSrc + '\n' + oInputs[i].value + '\n\n'; if (sSrc != '' && sSrc != oInputs[i].value) { sType = oInputs[i].value.replace(/.*\<embed[^\<]+type\=([\"\'])([^\"\']*)\1.*/mig, '$2'); if (sType == oInputs[i].value) { sType = ''; } sFlashVars = oInputs[i].value.replace(/.*\<embed[^\<]+flashvars\=([\"\'])([^\"\']*)\1.*/mig, '$2'); if (sFlashVars == oInputs[i].value) { sFlashVars = ''; } bEmbedFound = true; break; } } } if (!bEmbedFound) { sSrc = oEmbed.src; } oImageElement.setAttribute('src', sSrc); oImageElement.setAttribute('pluginspage', Clipmarks_GetAttribute(oEmbed, 'pluginspage', '')); oImageElement.setAttribute('width', Clipmarks_GetAttribute(oEmbed, 'width', 0)); oImageElement.setAttribute('height', Clipmarks_GetAttribute(oEmbed, 'height', 0)); if (sType != '') { oImageElement.appendChild(Clipmarks_ClipXML.createElement('type')).textContent = sType; } if (sFlashVars != '') { oImageElement.appendChild(Clipmarks_ClipXML.createElement('flashvars')).textContent = sFlashVars; } if (!bEmbedFound) { for (var i = 0; i < oEmbed.attributes.length; i++) { oAttribute = oEmbed.attributes[i]; if (oAttribute.name != 'style' && oAttribute.name != 'src' && oAttribute.name != 'pluginspage' && oAttribute.name != 'height' && oAttribute.name != 'width') { oImageElement.appendChild(Clipmarks_ClipXML.createElement(oAttribute.name)).textContent = oAttribute.value; } } } oFrameElement.appendChild(oImageElement); oImageElement = null; Clipmarks_ClipXML.documentElement.appendChild(oFrameElement); oFrameElement = null; } function Clipmarks_ClipHTMLElement(oTxtRange, bColumn) { var oSourceDocument = oTxtRange.ownerDocument; var oFrameElement = Clipmarks_ClipXML.createElement('frame'); var oElementXML = Clipmarks_ClipXML.createElement('content'); var oAttribute; var oParentElement; var i; var j; var k; var sContent = ''; oFrameElement.setAttribute('type', 'IHTMLTxtRange'); oFrameElement.setAttribute('background-color', oSourceDocument.bgColor); Clipmarks_DetectPermalink(oFrameElement, oTxtRange); Clipmarks_BuildSourceNode(oFrameElement, oSourceDocument); oElementXML.setAttribute('height', oTxtRange.clientHeight); oElementXML.setAttribute('width', oTxtRange.clientWidth); oElementXML.setAttribute('text-color', oSourceDocument.fgColor); oElementXML.setAttribute('link-color', oSourceDocument.linkColor); oElementXML.setAttribute('vlink-color', oSourceDocument.vlinkColor); if (oTxtRange.tagName == 'TR') { sContent = Clipmarks_GetOuterHTML(oTxtRange, true); oParentElement = oTxtRange.parentNode; while (oParentElement.tagName != 'TABLE') { oParentElement = oParentElement.parentNode; } oElementXML.appendChild(Clipmarks_ClipXML.createCDATASection('')); oElementXML.childNodes[0].textContent = '<table background="' + oParentElement.background + '" bgcolor="' + oParentElement.bgColor + '">' + sContent + '</table>'; } else if (oTxtRange.tagName == 'TD') { if (!bColumn) { sContent = Clipmarks_GetOuterHTML(oTxtRange, true); oParentElement = oTxtRange.parentNode; while (oParentElement.tagName != 'TABLE') { oParentElement = oParentElement.parentNode; } oElementXML.appendChild(Clipmarks_ClipXML.createCDATASection('')); oElementXML.childNodes[0].textContent = '<table background="' + oParentElement.background + '" bgcolor="' + oParentElement.bgColor + '"><tr>' + sContent + '</tr></table>'; } else { oParentElement = oTxtRange.parentNode; i = 0; while (i < oParentElement.childNodes.length) { if (oParentElement.childNodes[i] == oTxtRange) { break; } i++; } while (oParentElement.tagName != 'TABLE') { oParentElement = oParentElement.parentNode; } for (j = 0; j < oParentElement.childNodes.length; j++) { for (k = 0; k < oParentElement.childNodes[j].childNodes.length; k++) { if (oParentElement.childNodes[j].childNodes[k].childNodes[i]) { sContent += '<tr>' + Clipmarks_GetOuterHTML(oParentElement.childNodes[j].childNodes[k].childNodes[i], true) + '</tr>'; } } } oElementXML.appendChild(Clipmarks_ClipXML.createCDATASection('')); oElementXML.childNodes[0].textContent = '<table background="' + oParentElement.background + '" bgcolor="' + oParentElement.bgColor + '">' + sContent + '</table>'; } } else { oElementXML.appendChild(Clipmarks_ClipXML.createCDATASection('')); oElementXML.childNodes[0].textContent = Clipmarks_GetOuterHTML(oTxtRange, true); } oFrameElement.appendChild(oElementXML); oElementXML = null; Clipmarks_ClipXML.documentElement.appendChild(oFrameElement); oFrameElement = null; } function Clipmarks_ClipSelection(e) { if (!Clipmarks_IsContentSelected) { return; } var oSourceDocument = e.target.ownerDocument; var oWindow = oSourceDocument.defaultView; var oSelection = oWindow.getSelection(); var oRange = oSelection.getRangeAt(0); var oRange2 = oRange.cloneRange(); var oDiv = oSourceDocument.createElement("DIV"); oDiv.appendChild(oRange.cloneContents()); if (oDiv.innerHTML.length <= 0) { return; } var oFrameElement = Clipmarks_ClipXML.createElement('frame'); var oElementXML = Clipmarks_ClipXML.createElement('content'); var oAttribute; var oImage = null; oFrameElement.setAttribute('type', 'IHTMLTxtRange'); oFrameElement.setAttribute('selection', 'true'); oFrameElement.setAttribute('background-color', oSourceDocument.bgColor); oFrameElement.setAttribute('clip-index', Clipmarks_ClipElementIndex); Clipmarks_DetectPermalink(oFrameElement, oRange.commonAncestorContainer); Clipmarks_BuildSourceNode(oFrameElement, oSourceDocument); oElementXML.setAttribute('height', oRange.commonAncestorContainer.clientHeight); oElementXML.setAttribute('width', oRange.commonAncestorContainer.clientWidth); oElementXML.setAttribute('text-color', oSourceDocument.fgColor); oElementXML.setAttribute('link-color', oSourceDocument.linkColor); oElementXML.setAttribute('vlink-color', oSourceDocument.vlinkColor); oElementXML.appendChild(Clipmarks_ClipXML.createCDATASection(Clipmarks_GetInnerHTML(oDiv))); oFrameElement.appendChild(oElementXML); oElementXML = null; Clipmarks_ClipXML.documentElement.appendChild(oFrameElement); oFrameElement = null; oSelection.collapse(oSourceDocument.body, 0); if (oRange.endContainer == oRange.startContainer) { var oWrapper = oSourceDocument.createElement('SPAN'); oWrapper.setAttribute('clip-index', Clipmarks_ClipElementIndex); oWrapper.setAttribute('name', 'Clipmarks_SelectionBounds'); oWrapper.style.backgroundColor = '#4DC136'; oWrapper.style.display = 'inline'; oWrapper.style.position = 'relative'; oWrapper.style.fontSize = 'inherit !important'; oWrapper.style.fontWeight = 'inherit !important'; oWrapper.style.textDecoration = 'inherit !important'; oWrapper.style.color = 'inherit !important'; oWrapper.style.lineHeight = 'inherit !important'; oWrapper.style.overflow = 'visible'; oWrapper.style.left = '0px'; oWrapper.style.top = '0px'; oWrapper.style.padding = '0px'; oWrapper.style.margin = '0px'; oRange.surroundContents(oWrapper); oWrapper.addEventListener('click', Clipmarks_RemoveSelection, true); } else { oRange.collapse(true); oImage = oSourceDocument.createElement('IMG'); oImage.setAttribute('name', 'Clipmarks_SelectionBounds'); oImage.setAttribute('clip-index', Clipmarks_ClipElementIndex); oImage.setAttribute('style', 'display: inline !important;float:none;'); oImage.src = 'http://content0.clipmarks.com/images/selection-left.png'; oImage.style.position = 'relative'; oImage.style.margin = '0px'; oImage.style.marginBottom = '-3px'; oImage.style.border = '0'; oImage.style.cssFloat = 'none'; oImage.style.display = 'inline'; oRange.insertNode(oImage); oImage.addEventListener('click', Clipmarks_RemoveSelection, true); oRange2.collapse(false); oImage = oSourceDocument.createElement('IMG'); oImage.setAttribute('name', 'Clipmarks_SelectionBounds'); oImage.setAttribute('clip-index', Clipmarks_ClipElementIndex); oImage.setAttribute('style', 'display: inline !important;float:none;'); oImage.src = 'http://content0.clipmarks.com/images/selection-right.png'; oImage.style.position = 'relative'; oImage.style.marginBottom = '-3px'; oImage.style.border = '0'; oImage.style.cssFloat = 'none'; oImage.style.display = 'inline'; oRange2.insertNode(oImage); oImage.addEventListener('click', Clipmarks_RemoveSelection, true); } Clipmarks_ClipElementIndex++; Clipmarks_RemoveSelectionClipper(oSourceDocument); Clipmarks_CalcPopLimit(); } function Clipmarks_RemoveSelection(event) { var oElement = event.target; var oDocument = oElement.ownerDocument; while (Clipmarks_GetAttribute(oElement, 'name') != 'Clipmarks_SelectionBounds') { oElement = oElement.parentNode; } var lClipElementIndex = oElement.getAttribute('clip-index'); for (i = 1; i < Clipmarks_ClipXML.documentElement.childNodes.length; i++) { if (Clipmarks_ClipXML.documentElement.childNodes[i].getAttribute('clip-index') == lClipElementIndex) { Clipmarks_ClipXML.documentElement.removeChild(Clipmarks_ClipXML.documentElement.childNodes[i]); break; } } Clipmarks_RemoveSelectionBounds(oDocument, lClipElementIndex); Clipmarks_CalcPopLimit(); } function Clipmarks_RemoveSelectionClipper(oDocument) { if (oDocument.getElementById('Clipmarks_SelectionClipper')) { oDocument.body.removeChild(oDocument.getElementById('Clipmarks_SelectionClipper')); } } function Clipmarks_DetectPermalink(oFrameElement, oElement) { var oDoc = oElement.ownerDocument; var oLinks; var oLink; var i = 0; var oPermaLink = null; var bSkip = false; var oContainer = oElement; while (true) { i = 0; if (oContainer.tagName != null) { oLinks = oContainer.getElementsByTagName('A'); while (i < oLinks.length) { oLink = oLinks[i]; if (oLink.textContent.toLowerCase().indexOf('permanent link') != -1 || oLink.textContent.toLowerCase().indexOf('permalink') != -1) { if (oPermaLink != null) { if (oLink.href != oPermaLink.href) { bSkip = true; break; } } oPermaLink = oLink; } else if (oLink.hasAttribute('title')) { if (oLink.getAttribute('title').toLowerCase().indexOf('permanent link') != -1 || oLink.getAttribute('title').toLowerCase().indexOf('permalink') != -1) { if (oPermaLink != null) { if (oLink.href != oPermaLink.href) { bSkip = true; break; } } oPermaLink = oLink; } } oLink = null; i++; } } if (oPermaLink == null) { if (oContainer.nextSibling != null) { oContainer = oContainer.nextSibling; } else if (oContainer.tagName != 'BODY' && oContainer.parentNode != null) { oContainer = oContainer.parentNode; } else { break; } } else { break; } } if (oPermaLink != null && !bSkip) { oFrameElement.appendChild(Clipmarks_ClipXML.createElement('permalink')).textContent = oPermaLink.href; } } function Clipmarks_BuildSourceNode(oFrameElement, oSourceDocument) { var sSourcePath; var sSourcePage; var oSourceElement; var oElement; sSourcePath = oSourceDocument.location.pathname; sSourcePage = sSourcePath.substr(sSourcePath.lastIndexOf('/') + 1); sSourcePath = sSourcePath.substr(0, sSourcePath.lastIndexOf('/') + 1); oSourceElement = Clipmarks_ClipXML.createElement('source'); oElement = Clipmarks_ClipXML.createElement('base-href'); if (oSourceDocument.getElementsByTagName('BASE').length > 0) { oElement.textContent = oSourceDocument.getElementsByTagName('BASE')[oSourceDocument.getElementsByTagName('BASE').length - 1].href; } oSourceElement.appendChild(oElement); oElement = Clipmarks_ClipXML.createElement('protocol'); oElement.textContent = oSourceDocument.location.protocol; oSourceElement.appendChild(oElement); oElement = Clipmarks_ClipXML.createElement('host'); oElement.textContent = oSourceDocument.location.host; oSourceElement.appendChild(oElement); oElement = Clipmarks_ClipXML.createElement('path'); oElement.textContent = sSourcePath; oSourceElement.appendChild(oElement); oElement = Clipmarks_ClipXML.createElement('page'); oElement.textContent = sSourcePage; oSourceElement.appendChild(oElement); oElement = Clipmarks_ClipXML.createElement('query'); oElement.textContent = oSourceDocument.location.search; oSourceElement.appendChild(oElement); oFrameElement.appendChild(oSourceElement); } function Clipmarks_HighlightElementClick(event) { Clipmarks_RemoveElement(event.target); } function Clipmarks_RemoveElement(oOverlay) { var oDocument = oOverlay.ownerDocument; while (oOverlay.id == 'Clipmarks_HighlightDivChild') { oOverlay = oOverlay.parentNode; } var j = 0; var i = 0; var oOverlays = new Array(); var oElements = new Array(); var lClipElementIndex = oOverlay.getAttribute('clip-index'); var oSupportingNodes = oDocument.getElementsByName('Clipmarks_SupportNode' + lClipElementIndex); for (i = oSupportingNodes.length - 1; i >= 0; i--) { oDocument.body.removeChild(oSupportingNodes[i]); } for (i = 0; i < Clipmarks_ClipOverlays.length; i++) { if (lClipElementIndex == Clipmarks_ClipOverlays[i].getAttribute('clip-index')) { oDocument.body.removeChild(Clipmarks_ClipOverlays[i]); for (j = 1; j < Clipmarks_ClipXML.documentElement.childNodes.length; j++) { if (Clipmarks_ClipXML.documentElement.childNodes[j].getAttribute('clip-index') == lClipElementIndex) { Clipmarks_ClipXML.documentElement.removeChild(Clipmarks_ClipXML.documentElement.childNodes[j]); break; } } } else { oOverlays[oOverlays.length] = Clipmarks_ClipOverlays[i]; oElements[oElements.length] = Clipmarks_ClipElements[i]; } } Clipmarks_ClipOverlays = oOverlays; Clipmarks_ClipElements = oElements; Clipmarks_CalcPopLimit(); } function Clipmarks_ClearOverlays() { var oDocument; var i = 0; var j = 0; var oSupportingNodes = null; for (i = (Clipmarks_ClipOverlays.length - 1); i >= 0 ; i--) { oDocument = Clipmarks_ClipOverlays[i].ownerDocument; oSupportingNodes = oDocument.getElementsByName('Clipmarks_SupportNode' + Clipmarks_ClipOverlays[i].getAttribute('clip-index')); for (j = oSupportingNodes.length - 1; j >= 0; j--) { oDocument.body.removeChild(oSupportingNodes[j]); } oDocument.body.removeChild(Clipmarks_ClipOverlays[i]); } Clipmarks_InitXML(); Clipmarks_ClipOverlays = new Array(); Clipmarks_ClipElements = new Array(); } function Clipmarks_Navigate(event, type) { var win = window._content.document; var URL; switch(type) { case 'home': URL = CLIPMARKS_URL_HOME; break; case 'public_library': URL = CLIPMARKS_URL_PUBLIC_LIBRARY; break; case 'my_library': URL = CLIPMARKS_URL_MY_LIBRARY; break; case 'my_widget': URL = CLIPMARKS_URL_MY_WIDGET; break; case 'settings': URL = CLIPMARKS_URL_MY_PROFILE; break; case 'help': URL = CLIPMARKS_URL_HELP; break; } Clipmarks_LoadURL(URL); } function Clipmarks_LoadURL(URL) { window._content.document.location = URL; window.content.focus(); }